#include "Parser.h"
#include <iostream>
#include <list>

using namespace std;

int main() {
list<string> ParQuery;
list<string>::iterator Q = ParQuery.begin();
list<>
string Query;
string a;
int i;
Parser parse;
string temp;

parse.setBeginIte();
while (a.compare("quit") != 0)
{
	cin >> a;
	if(a.compare("fact.")==0)		// Input Fact Rule
	{
	a.clear();
	while (a.compare("end.") != 0) {
			cout << "\n[F] ";
			getline(cin,a);
			if (a.compare("end.") != 0) {
				parse.setLine(a);
				if(!parse.isRules(a)){parse.ParseInput();}
				else {cout << "\nBukan Fact";}
				a.clear();
			}
		}
		cin >> a;
	}
	else (a.compare("rule.")==0)
	{
	a.clear();
	while (a.compare("end.") != 0) {
			cout << "\n[R] ";
			getline(cin,a);
			if (a.compare("end.") != 0) {
				parse.setLine(a);
				if(parse.isRules(a)){parse.ParseInput();}
				else {cout << "\nBukan Rule!";}
				a.clear();
			}
		}
		cin >> a;
	}
	else		// Query
	{
		// while(a.at(i) != '('){Query.push_back(a.at(i)); i++;}
		// i++;
		// while (a.at(i)!='.')
			// {
			// if(a.at(i) == ' '){parse.IgnoreBlank(a,&i);}
			// else if ((a.at(i) == ',') || (a.at(i) == ')')) {ParQuery.push_back(temp); temp.clear(); i++;}
			// else {temp.push_back(a.at(i)); i++;}
			// }
		// parse.searchFR(Query);
		// if(parse.ite != parse.fakta.end()){temp = parse.getFR();}
		// while(parse.ite != parse.fakta.end())
			// {
			// if (parse.(*ite)->IsRULE() == true) {
										// if (parse.IsVariable(*Q)) {
																	
																	// }
										// }							
			// else {			// Jika query ada di bagian fakta
				   // if (parse.IsVariable(*Q))
						// {
						
						// }
				// }
			// }
}
	list<Facts*>::iterator it;
	for (  it =  parse.getFacts()->begin(); it != parse.getFacts()->end(); it++) {
			// cout << (*it);
			// cout << (it == parse.getFacts()->end()) << endl;
			// cout << (*it)->getName() << "\n JumPar : " << parse.getJumParam() << endl;
			if ((*it)->IsRULE()) {
				Facts* F = *it;
				Rules* G = (Rules*)F;
				G->CekParamR();
				G->CekRule();
				cout <<"NAMA: " << G->getName() <<  "\n IsRule? " << (*it)->IsRULE() << "   JumRel : " << parse.getJumRel() << endl;
			}
			
			else{
				for (list<Parameter*>::iterator ite = (*it)->getListParam()->begin(); ite != (*it)->getListParam()->end();ite++) {
					cout << "PARAM =   " << (*ite)->GetParam() <<endl;
				}	
			}
			//++it;
	}
	
	return 0;
}
